﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace SuSPExtension
{
	// Token: 0x02000004 RID: 4
	public class GlobalKeyBind
	{
		// Token: 0x06000009 RID: 9
		[DllImport("user32.dll")]
		private static extern bool RegisterHotKey(IntPtr hWnd, int id, int modifiers, Keys vk);

		// Token: 0x0600000A RID: 10
		[DllImport("user32.dll")]
		private static extern bool UnregisterHotKey(IntPtr hWnd, int id);

		// Token: 0x0600000B RID: 11 RVA: 0x000024E8 File Offset: 0x000006E8
		public void Regist(IntPtr hWnd, int modifiers, SuKeys vk, GlobalKeyBind.HotKeyCallBackHanlder callBack)
		{
			int num = this.keyid;
			this.keyid = num + 1;
			int num2 = num;
			if (!GlobalKeyBind.RegisterHotKey(hWnd, num2, modifiers, (Keys)vk))
			{
				throw new Exception("注册失败！");
			}
			this.keymap[num2] = callBack;
		}

		// Token: 0x0600000C RID: 12 RVA: 0x0000252C File Offset: 0x0000072C
		public void UnRegist(IntPtr hWnd, GlobalKeyBind.HotKeyCallBackHanlder callBack)
		{
			foreach (KeyValuePair<int, GlobalKeyBind.HotKeyCallBackHanlder> keyValuePair in this.keymap)
			{
				if (keyValuePair.Value == callBack)
				{
					GlobalKeyBind.UnregisterHotKey(hWnd, keyValuePair.Key);
					break;
				}
			}
		}

		// Token: 0x0600000D RID: 13 RVA: 0x00002598 File Offset: 0x00000798
		public void ProcessHotKey(Message m)
		{
			if (m.Msg == 786)
			{
				int key = m.WParam.ToInt32();
				GlobalKeyBind.HotKeyCallBackHanlder hotKeyCallBackHanlder;
				if (this.keymap.TryGetValue(key, out hotKeyCallBackHanlder))
				{
					hotKeyCallBackHanlder();
				}
			}
		}

		// Token: 0x04000032 RID: 50
		private int keyid = 10;

		// Token: 0x04000033 RID: 51
		private Dictionary<int, GlobalKeyBind.HotKeyCallBackHanlder> keymap = new Dictionary<int, GlobalKeyBind.HotKeyCallBackHanlder>();

		// Token: 0x0200000D RID: 13
		// (Invoke) Token: 0x0600008A RID: 138
		public delegate void HotKeyCallBackHanlder();

		// Token: 0x0200000E RID: 14
		public enum HotkeyModifiers
		{
			// Token: 0x04000094 RID: 148
			Alt = 1,
			// Token: 0x04000095 RID: 149
			Control,
			// Token: 0x04000096 RID: 150
			Shift = 4,
			// Token: 0x04000097 RID: 151
			Win = 8
		}
	}
}
